from symtable import Class

from Demos.win32ts_logoff_disconnected import username
from flask import Flask,render_template
from datetime import datetime

app = Flask(__name__)
#过滤器的使用
def datetime_format(value,format='%Y年%m月%d日 %H:%M'):
    return value.strftime(format)

app.add_template_filter(datetime_format,'dformat')

class User:
    def __init__(self,username,email):
        self.username = username
        self.email = email

@app.route('/')
def hello_world():  # put application's code here
    user = User(username="圣诞树",email="xxx@qq.com")
    person = {
        "username" : "张三",
        "email" : "zhangsan@qq.com"
    }
    return render_template('index.html',user=user,person=person)

@app.route('/book/<book_id>')
def book(book_id):
    return render_template("book_detail.html",book_id=book_id,username="案例")

@app.route("/filter")
def filter():
    user = User(username="圣诞树xxx",email="xxx@qq.com")
    mytime = datetime.now()
    return render_template('filter.html',user=user,mytime=mytime)
#控制语句
@app.route("/control")
def control_statement():
    age = 17
    books = [
        {
            "name":"三国",
            "author":"罗贯中"
        },{
            "name":"西游记",
            "author":"作者"
        }
    ]
    return render_template("control.html",age=age,books=books)
#继承
@app.route("/child1")
def child1():
    return render_template("child1.html")

@app.route("/child2")
def child2():
    return render_template("child2.html")

@app.route("/static")
def static_dome():
    return render_template("static.html")



if __name__ == '__main__':
    app.run()
